home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / doc / Interp.3 < prev    next >
Text File  |  1993-01-31  |  6KB  |  128 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/Interp.3,v 1.8 93/01/31 15:35:37 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .so man.macros
  13. .HS Tcl_Interp tcl
  14. .BS
  15. .SH NAME
  16. Tcl_Interp \- client-visible fields of interpreter structures
  17. .SH SYNOPSIS
  18. .nf
  19. \fB#include <tcl.h>\fR
  20. .sp
  21. typedef struct {
  22.     char *\fIresult\fR;
  23. .VS
  24.     Tcl_FreeProc *\fIfreeProc\fR;
  25. .VE
  26.     int \fIerrorLine\fR;
  27. } Tcl_Interp;
  28.  
  29. .VS
  30. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  31. .VE
  32. .BE
  33.  
  34. .SH DESCRIPTION
  35. .PP
  36. The \fBTcl_CreateInterp\fR procedure returns a pointer to a Tcl_Interp
  37. structure.  This pointer is then passed into other Tcl procedures
  38. to process commands in the interpreter and perform other operations
  39. on the interpreter.  Interpreter structures contain many many fields
  40. that are used by Tcl, but only three that may be accessed by
  41. .VS
  42. clients:  \fIresult\fR, \fIfreeProc\fR, and \fIerrorLine\fR.
  43. .PP
  44. The \fIresult\fR and \fIfreeProc\fR fields are used to return
  45. results or error messages from commands.
  46. This information is returned by command procedures back to \fBTcl_Eval\fR,
  47. and by \fBTcl_Eval\fR back to its callers.
  48. The \fIresult\fR field points to the string that represents the
  49. result or error message, and the \fIfreeProc\fR field tells how
  50. to dispose of the storage for the string when it isn't needed anymore.
  51. The easiest way for command procedures to manipulate these
  52. fields is to call procedures like \fBTcl_SetResult\fR
  53. or \fBTcl_AppendResult\fR;  they
  54. will hide all the details of managing the fields.
  55. The description below is for those procedures that manipulate the
  56. fields directly.
  57. .PP
  58. Whenever a command procedure returns, it must ensure
  59. that the \fIresult\fR field of its interpreter points to the string
  60. being returned by the command.
  61. The \fIresult\fR field must always point to a valid string.
  62. If a command wishes to return no result then \fIinterp->result\fR
  63. should point to an empty string.
  64. Normally, results are assumed to be statically allocated,
  65. which means that the contents will not change before the next time
  66. \fBTcl_Eval\fR is called or some other command procedure is invoked.
  67. In this case, the \fIfreeProc\fR field must be zero.
  68. Alternatively, a command procedure may dynamically
  69. allocate its return value (e.g. using \fBmalloc\fR)
  70. and store a pointer to it in \fIinterp->result\fR.
  71. In this case, the command procedure must also set \fIinterp->freeProc\fR
  72. to the address of a procedure that can free the value (usually \fBfree\fR).
  73. If \fIinterp->freeProc\fR is non-zero, then Tcl will call \fIfreeProc\fR
  74. to free the space pointed to by \fIinterp->result\fR before it
  75. invokes the next command.
  76. If a client procedure overwrites \fIinterp->result\fR when
  77. \fIinterp->freeProc\fR is non-zero, then it is responsible for calling
  78. \fIfreeProc\fR to free the old \fIinterp->result\fR (the \fBTcl_FreeResult\fR
  79. macro should be used for this purpose).
  80. .PP
  81. \fIFreeProc\fR should have arguments and result that match the
  82. \fBTcl_FreeProc\fR declaration above:  it receives a single
  83. argument which is a pointer to the result value to free.
  84. In most applications \fBfree\fR is the only non-zero value ever
  85. used for \fIfreeProc\fR.
  86. However, an application may store a different procedure address
  87. in \fIfreeProc\fR in order to use an alternate memory allocator
  88. or in order to do other cleanup when the result memory is freed.
  89. .PP
  90. As part of processing each command, \fBTcl_Eval\fR initializes
  91. \fIinterp->result\fR
  92. and \fIinterp->freeProc\fR just before calling the command procedure for
  93. the command.  The \fIfreeProc\fR field will be initialized to zero,
  94. and \fIinterp->result\fR will point to an empty string.  Commands that
  95. do not return any value can simply leave the fields alone.
  96. .VE
  97. Furthermore, the empty string pointed to by \fIresult\fR is actually
  98. part of an array of \fBTCL_RESULT_SIZE\fR characters (approximately 200).
  99. If a command wishes to return a short string, it can simply copy
  100. it to the area pointed to by \fIinterp->result\fR.  Or, it can use
  101. the sprintf procedure to generate a short result string at the location
  102. pointed to by \fIinterp->result\fR.
  103. .PP
  104. It is a general convention in Tcl-based applications that the result
  105. of an interpreter is normally in the initialized state described
  106. in the previous paragraph.
  107. Procedures that manipulate an interpreter's result (e.g. by
  108. returning an error) will generally assume that the result
  109. has been initialized when the procedure is called.
  110. If such a procedure is to be called after the result has been
  111. changed, then \fBTcl_ResetResult\fR should be called first to
  112. reset the result to its initialized state.
  113. .PP
  114. The \fIerrorLine\fR
  115. field is valid only after \fBTcl_Eval\fR returns
  116. a \fBTCL_ERROR\fR return code.  In this situation the \fIerrorLine\fR
  117. field identifies the line number of the command being executed when
  118. the error occurred.  The line numbers are relative to the command
  119. being executed:  1 means the first line of the command passed to
  120. \fBTcl_Eval\fR, 2 means the second line, and so on.
  121. The \fIerrorLine\fR field is typically used in conjunction with
  122. \fBTcl_AddErrorInfo\fR to report information about where an error
  123. occurred.
  124. \fIErrorLine\fR should not normally be modified except by \fBTcl_Eval\fR.
  125.  
  126. .SH KEYWORDS
  127. free, initialized, interpreter, malloc, result
  128.